 // 根据编码范围 生成字符=>放到数组中
 var numList = [];
 for (var i = 48; i <= 57; i++) {
     var char = String.fromCharCode(i);
     numList.push(char);
 }
 console.log(numList);

 var bigList = [];
 for (var i = 65; i <= 90; i++) {
     var char = String.fromCharCode(i);
     bigList.push(char);
 }
 console.log(bigList);

 var smallList = [];
 for (var i = 97; i <= 122; i++) {
     var char = String.fromCharCode(i);
     smallList.push(char);
 }
 console.log(smallList);

 var speList = ["_"]; // 允许使用的特殊字符

 var normalList = numList.concat(bigList, smallList, speList);
 console.log(normalList);


 function randCode(len) {
    // 参数的默认值   len 默认4
    // len = len == undefined ? 4 : len;  // 三目运算符
    len = len || 4;  // len有值 就只用len 否则len = 4


     var randList = numList.concat(bigList, smallList);
     var str = "";
     for (var i = 0; i < len; i++) {
         var index = Math.floor(Math.random()*randList.length);
         var char = randList[index];
         if(str.indexOf(char)==-1){
             str += char;
         }else{
             i--;
         }
     }
     return str;
 }